//
// Created by weslywang on 2020/7/3.
//
#include "../common/common.h"


map<Node *, Node *> likeMap;

Node *cloneGraph(Node *node) {
    if (node == NULL)
        return node;
    if (likeMap[node])
        return likeMap[node];

    Node *cloned = new Node(node->val);
    likeMap[node] = cloned;

    for (auto nei: node->neighbors) {
        cloned->neighbors.push_back(cloneGraph(nei));
    }
    return cloned;
}